<?php
namespace SmartDevice;

use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use SmartDevice\Model\OwnerTable;
use SmartDevice\Model\Owner;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module
{

	public function getAutoloaderConfig()
	{
		return array(
				'Zend\Loader\ClassMapAutoloader' => array(
						__DIR__ . '/autoload_classmap.php'
				),
				'Zend\Loader\StandardAutoloader' => array(
						'namespaces' => array(
								__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
						)
				)
		);
	}

	public function getConfig()
	{
		return include __DIR__ . '/config/module.config.php';
	}

	// Add this method:
	public function getServiceConfig()
	{
		return array(
				'factories' => array(
						'SmartDevice\Model\OwnerTable' => function ($sm)
						{
							$tableGateway = $sm->get('OwnerTableGateway');
							$table = new OwnerTable($tableGateway);
							return $table;
						},
						'OwnerTableGateway' => function ($sm)
						{
							$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
							$resultSetPrototype = new ResultSet();
							$resultSetPrototype->setArrayObjectPrototype(new Owner());
							return new TableGateway('owner', $dbAdapter, null, $resultSetPrototype);
						}
				)
		);
	}
}